package com.wuhao.shootclient.util.eventbus;

import org.greenrobot.eventbus.EventBus;

/**
 * @author sauce
 * @since 2018/10/13
 */
public class AppEventBus {
    private EventBus bus;
    private static AppEventBus INSTANCE;

    public static AppEventBus getInstance() {
        if (INSTANCE == null) {
            INSTANCE = new AppEventBus();
        }
        return INSTANCE;
    }

    public AppEventBus() {
        bus = EventBus.builder()
                .logNoSubscriberMessages(false)
                .build();
    }


    public void register(Object object) {
        bus.register(object);
    }

    public void unregister(Object object) {
        bus.unregister(object);
    }

    /**
     * @param object 需要判断的实例
     * @return 已经注册
     */
    public boolean isRegistered(Object object) {
        return bus.isRegistered(object);
    }

    /**
     * @param code eventBus Code
     */
    public void post(int code) {
        bus.post(new EventCenter(code));
    }

    public void post(int code, Object... t) {
        bus.post(new EventCenter(code, t));
    }

    public void postSticky(int code) {
        bus.postSticky(new EventCenter(code));
    }

    public void postSticky(int code, Object... t) {
        bus.postSticky(new EventCenter(code, t));
    }


}
